home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / gnu_st.lha / gnu_st / smalltalk-1.1.1 / stix / CFuncs.st < prev    next >
Text File  |  1991-09-12  |  9KB  |  371 lines

  1. "======================================================================
  2. |
  3. |   SystemDictionary Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbyrne      8 Jul 89      Created.
  34. |
  35. "
  36.  
  37. Object variableSubclass: #CFunctionDescriptor
  38.        instanceVariableNames: 'cFunction cFunctionName returnType numFixedArgs'
  39.        classVariableNames: ''
  40.        poolDictionaries: ''
  41.        category: nil !
  42.  
  43. CFunctionDescriptor comment: 
  44. 'I am not part of the Smalltalk definition.  My instances contain information
  45. about C functions that can be called from within Smalltalk, such as number
  46. and type of parameters.  This information is used by the C callout mechanism
  47. to perform the actual call-out to C routines.' !
  48.  
  49.  
  50. "A couple of simple, but useful callout functions, as examples."
  51.  
  52. Behavior defineCFunc: 'system'
  53.          withSelectorArgs: 'system: aString'
  54.      forClass: SystemDictionary
  55.      returning: #int
  56.      args: #(string)!
  57.  
  58. Behavior defineCFunc: 'getenv'
  59.          withSelectorArgs: 'getenv: aString'
  60.      forClass: SystemDictionary
  61.      returning: #string
  62.      args: #(string)!
  63.  
  64.  
  65. Smalltalk at: #XGlobals put: (Dictionary new)!
  66. XGlobals at: #Registry put: (Dictionary new)!
  67.  
  68. FileStream fileIn: 'X.st'.
  69. FileStream fileIn: 'XPacket.st'!
  70.  
  71.  
  72.  
  73. Object subclass: #Display
  74.        instanceVariableNames: 'socket majorVersion minorVersion releaseNum resourceIdBase
  75.                                resourceIdMask motionBufferSize maxRequestLen imageByteOrder
  76.                                bitmapBitOrder bitmapFormatScanUnit bitmapFormatScanPad 
  77.                                minKeycode maxKeycode vendorName formats screens idCounter'
  78.        classVariableNames: ''
  79.        poolDictionaries: ''
  80.        category: 'X hacking'
  81. !
  82.  
  83. Object subclass: #Format
  84.        instanceVariableNames: 'depth bitsPerPixel scanlinePad'
  85.        classVariableNames: ''
  86.        poolDictionaries: ''
  87.        category: 'X hacking'
  88. !
  89.  
  90. Object subclass: #Screen
  91.        instanceVariableNames: 'window defaultColormap whitePixel blackPixel
  92.                                currentInputMasks widthPixels heightPixels
  93.                                widthMM heightMM minInstalledMaps maxInstalledMaps
  94.                                rootVisual backingStores saveUnders rootDepth
  95.                                depths'
  96.        classVariableNames: ''
  97.        poolDictionaries: ''
  98.        category: 'X hacking'
  99. !
  100.  
  101. Object subclass: #Depth
  102.        instanceVariableNames: 'depth visuals'
  103.        classVariableNames: ''
  104.        poolDictionaries: ''
  105.        category: 'X hacking'
  106. !
  107.  
  108. Object subclass: #VisualType
  109.        instanceVariableNames: 'visualId class bitsPerRGB colormapEntries 
  110.                                redMask greenMask blueMask'
  111.        classVariableNames: ''
  112.        poolDictionaries: ''
  113.        category: 'X hacking'
  114. !
  115.  
  116.  
  117.  
  118. !Display class methodsFor: 'instance creation'!
  119.  
  120. host: hostName display: anInteger
  121.     | xStream result |
  122.     xStream _ X connectTo: hostName display: anInteger.
  123.  
  124.     xStream char: (Bigendian ifTrue: [ $B ] ifFalse: [ $l ]).
  125.     xStream byte: 0.
  126.     
  127.     xStream word: 11.
  128.     xStream word: 0.
  129.     xStream word: 0.        "length of auth string"
  130.     xStream word: 0.        "length of auth data"
  131.     xStream word: 0.        "unused"
  132.     
  133.     xStream byte == 1        "succeeded?"
  134.     ifTrue: [ xStream byte.    "unused here "
  135.           ^self new: xStream ]
  136.     ifFalse: [ ^nil ]    "maybe issue an error?"
  137. !
  138.  
  139. new: fromStream
  140.     ^self new init: fromStream
  141. !!
  142.  
  143.  
  144. !Display methodsFor: 'accessing'!
  145.  
  146. socket
  147.     ^socket
  148. !
  149.  
  150. nextId
  151.     | id |
  152.     id _ resourceIdBase bitOr: (idCounter bitAnd:  resourceIdMask).
  153.     idCounter _ idCounter + 1.
  154.     ^id
  155. !!
  156.  
  157.  
  158. !Display methodsFor: 'private'!
  159.  
  160. init: xStream
  161.     | vendorLen numScreens numFormats |
  162.  
  163.     idCounter _ 0.
  164.  
  165.     socket _ xStream.
  166.  
  167.     majorVersion _ socket uword.
  168.     minorVersion _ socket uword.
  169.     socket uword.        "skip length"
  170.  
  171.     releaseNum _ socket ulong.
  172.     resourceIdBase _ socket ulong.
  173.     BaseId _ resourceIdBase.
  174.     resourceIdMask _ socket ulong.
  175.     BaseMask _ resourceIdMask.
  176.  
  177.     motionBufferSize _ socket ulong.
  178.     vendorLen _ socket uword.
  179.     maxRequestLen _ socket uword.
  180.     numScreens _ socket ubyte.
  181.     numFormats _ socket ubyte.
  182.  
  183.     imageByteOrder _ socket byte.
  184.     bitmapBitOrder _ socket byte.
  185.     bitmapFormatScanUnit _ socket ubyte.
  186.     bitmapFormatScanPad _ socket ubyte.
  187.     minKeycode _ socket ubyte.
  188.     maxKeycode _ socket ubyte.
  189.     socket long.            "ignored "
  190.     
  191.     vendorName _ socket getString: vendorLen.    
  192.  
  193.     formats _ Array new: numFormats.
  194.     screens _ Array new: numScreens.
  195.  
  196.     1 to: numFormats do: 
  197.     [ :i | formats at: i put: (Format new: socket) ].
  198.     1 to: numScreens do: 
  199.     [ :i | screens at: i put: (Screen new: socket) ]
  200. !!
  201.  
  202.  
  203. !Format class methodsFor: 'instance creation'!
  204.  
  205. new: xStream
  206.     ^self new init: xStream
  207. !!
  208.  
  209. !Format methodsFor: 'private'!
  210.  
  211. init: socket
  212.     depth _ socket ubyte.
  213.     bitsPerPixel _ socket ubyte.
  214.     scanlinePad _ socket ubyte.
  215.     5 timesRepeat: [ socket ubyte ] "skip trailing junk"
  216. !!
  217.  
  218.  
  219. !Screen class methodsFor: 'instance creation'!
  220.  
  221. new: xStream
  222.     ^self new init: xStream
  223. !!
  224.  
  225. !Screen methodsFor: 'private'!
  226.  
  227. init: socket
  228.     | depthsAllowed |
  229.  
  230.     window _ socket ulong.
  231.     RootWindowID isNil
  232.     ifTrue: [ RootWindowID _ window ]. "only want first one"
  233.     defaultColormap _ socket ulong.
  234.     whitePixel _ socket ulong.
  235.     blackPixel _ socket ulong.
  236.  
  237. WhitePixel _ whitePixel.
  238. BlackPixel _ blackPixel.
  239.  
  240.     currentInputMasks _ socket ulong.
  241.     widthPixels _ socket uword.
  242.     heightPixels _ socket uword.
  243.     widthMM _ socket uword.
  244.     heightMM _ socket uword.
  245.  
  246.     minInstalledMaps _ socket uword.
  247.     maxInstalledMaps _ socket uword.
  248.     rootVisual _ socket ulong.
  249.     backingStores _ socket byte.
  250.  
  251.     saveUnders _ socket byte.
  252.     rootDepth _ socket byte.
  253.     depthsAllowed _ socket byte.
  254.  
  255.     depths _ Array new: depthsAllowed.
  256.     
  257.     1 to: depthsAllowed do:
  258.     [ :i | depths at: i put: (Depth new: socket) ]
  259. !!
  260.  
  261.  
  262. !Depth class methodsFor: 'instance creation'!
  263.  
  264. new: xStream
  265.     ^self new init: xStream
  266. !!
  267.  
  268.  
  269. !Depth methodsFor: 'private'!
  270.  
  271. init: socket
  272.     | numVisuals |
  273.     depth _ socket byte.
  274.  
  275.     socket byte.        " ignore "
  276.     numVisuals _ socket word.
  277.     socket long.        " pad "
  278.     
  279.     visuals _ Array new: numVisuals.
  280.  
  281.     1 to: numVisuals do:
  282.     [ :i | visuals at: i put: (VisualType new: socket) ]
  283. !!
  284.  
  285.  
  286.  
  287.  
  288. !VisualType class methodsFor: 'instance creation'!
  289.  
  290. new: xStream
  291.     ^self new init: xStream
  292. !!
  293.  
  294.  
  295. !VisualType methodsFor: 'accessing'!
  296.  
  297. id
  298.     ^visualId
  299. !!
  300.  
  301.  
  302. !VisualType methodsFor: 'private'!
  303.  
  304. init: socket
  305.     | visualId class bitsPerRGB colormapEntries redMask greenMask blueMask |
  306.  
  307.     visualId _ socket long.
  308.  
  309. VisualId isNil
  310.     ifTrue: [ VisualId _ visualId ]. "pick up first (bw)"
  311.  
  312.     class _ socket byte.
  313.   
  314. "(#(StaticGray GrayScale StaticColor PseudoColor TrueColor DirectColor)
  315.    at: class + 1) bugOut: 'Display type: '."
  316.  
  317.     bitsPerRGB _ socket byte.
  318.  
  319.     colormapEntries _ socket word.
  320.  
  321.     redMask _ socket long.
  322.     greenMask _ socket long.
  323.     blueMask _ socket long.
  324.  
  325.     socket long            " ignored "
  326. !!
  327.  
  328.  
  329.  
  330. FileStream fileIn: 'Point.st'!
  331. FileStream fileIn: 'Rectangle.st'!
  332.  
  333. FileStream fileIn: 'error.st'!
  334. FileStream fileIn: 'event.st'!
  335.  
  336. FileStream fileIn: 'Atom.st'!
  337.  
  338. FileStream fileIn: 'TextItem.st'!
  339.  
  340. !X methodsFor: 'reading'!
  341.  
  342. getPacket
  343.     | type err |
  344.     type _ self byte.
  345.     type == 0 ifTrue: [ err _ XError newFrom: self.
  346.             err inspect.
  347.             ^nil ].
  348.     type > 1 ifTrue: [ ^XEvent newFrom: self type: type ]
  349. !
  350.  
  351. getReply
  352.     | err |
  353.     (self byte) == 0
  354.     ifTrue: [ err _ XError newFrom: self.
  355.           err inspect.
  356.           ^false ].
  357.     self byte.            "skip the unused reply value"
  358.     self word.            "skip the sequence number"
  359.     self long.            "skip the length"
  360.     ^true
  361. !!
  362.  
  363. FileStream fileIn: 'Arc.st'!
  364. FileStream fileIn: 'Drawable.st'!
  365. FileStream fileIn: 'GC.st'!
  366. FileStream fileIn: 'Window.st'!
  367. FileStream fileIn: 'Pixmap.st'!
  368. FileStream fileIn: 'Pen.st'!
  369.